import QtQuick
import QtQuick.Window
import QtQml.Models

Column {
    height: 160
    spacing: 2

//    // Case1: 数字作为model
//    Repeater {
//        model: 100
//        delegate: BlueBox {
//            required property int index
//            width: 160; height: 30
//            text: index
//        }
//        onItemAdded: console.log("item"+index+" added")
//    }

//    // Case2: 数组作为model
//    Repeater {
//        model: ["Enterprise", "Columbia", "Challenger", "Discovery", "Endeavor", "Atlantis"]

//        delegate: BlueBox {
//            required property var modelData
//            required property int index
//            width: 160; height: 30
//            text: modelData + '(' + index + ')'
//        }
//        onItemAdded: console.log("item"+index+" added")
//    }

    // Case3: 内置ListModel作为model
    Repeater {
        model: ListModel {
            ListElement { name: "Mercury"; surfaceColor: "gray" }
            ListElement { name: "Venus"; surfaceColor: "yellow" }
            ListElement { name: "Earth"; surfaceColor: "blue" }
            ListElement { name: "Mars"; surfaceColor: "orange" }
            ListElement { name: "Jupiter"; surfaceColor: "orange" }
            ListElement { name: "Saturn"; surfaceColor: "yellow" }
            ListElement { name: "Uranus"; surfaceColor: "lightBlue" }
            ListElement { name: "Neptune"; surfaceColor: "lightBlue" }
        }

        delegate: BlueBox {
            required property string name
            required property color surfaceColor
            width: 160; height: 30
            radius: 3
            text: name

            Rectangle {
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
                anchors.leftMargin: 4
                width: 16; height: 16; radius: 8
                color: parent.surfaceColor
            }
        }
        onItemAdded: console.log("item"+index+" added")
    }
}
